package com.daxidi.cn.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.daxidi.cn.entity.Shop;
import com.daxidi.cn.entity.ShopType;
import com.daxidi.cn.mapper.ShopTypeMapper;
import com.daxidi.cn.service.IShopTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 商家类型 服务实现类
 * </p>
 *
 * @author wsh
 * @since 2020-11-09
 */
@Service
public class ShopTypeServiceImpl extends ServiceImpl<ShopTypeMapper, ShopType> implements IShopTypeService {
    @Autowired
    private ShopTypeMapper shopTypeMapper;
    @Override
    public void addShopType(ShopType shopType) {
        shopTypeMapper.insert(shopType);
    }

    @Override
    public void deleteShopTypeById(Integer id) {
        shopTypeMapper.deleteById(id);
    }

    @Override
    public void updateShopTypeById(ShopType shopType) {
        shopTypeMapper.updateById(shopType);
    }

    @Override
    public Map selectShopTypesPage(Integer pageNum, Integer pageSize) {
        Page<ShopType> page = new Page<>(pageNum, pageSize);
        Page<ShopType> shopTypePage = shopTypeMapper.selectPage(page, null);
        long total = shopTypePage.getTotal();
        List<ShopType> shopTypes = shopTypePage.getRecords();
        Map map = new HashMap();
        map.put("data",shopTypes);
        map.put("count",total);
        return map;
    }

    @Override
    public ShopType selectShopType(Integer id) {
        QueryWrapper<ShopType> wrapper = new QueryWrapper<>();
        wrapper.eq("id",id);
        ShopType shopType = shopTypeMapper.selectOne(wrapper);
        return shopType;
    }

    @Override
    public List<ShopType> showAllShopType() {
        List<ShopType> shopTypes = shopTypeMapper.selectList(null);
        return shopTypes;
    }

}
